<?php
namespace app\admin\controller;

use \think\Controller;
use \think\Db;
use \think\captcha\Captcha;
use \think\Request;
use \think\Session;
class Login extends Controller{
    public function index()
    {
        // var_dump(password_hash('admin',PASSWORD_DEFAULT));
        return $this->fetch();
    }
    public function init(Request $re){
        $code       = $re->param('code');
        $captcha    = new Captcha();
        // $is_captcha = $captcha->check($code);
        // if($is_captcha){
            $name       = $re->param('name');
            $data = Db::table('de_user')->where(['u_name'=>$name])->select();
            if(!empty($data)){
                $password   = $re->param('password');
                $verify = password_verify($password,$data[0]['u_password']);
                if($verify){
                    $info = ['id','name','agent'];
                    $agent = md5($_SERVER['HTTP_USER_AGENT']);
                    $token = md5('key'.$data[0]['u_id'])
                    Session::set('info.id',$data[0]['u_id']);
                    Session::set('indo.name',$data[0]['u_name']);
                    $this->redirect('/public/index.php/admin/index/index');
                    // $this->redirect(url('index'));
                }else{
                    $this->error('你输入的密码不正确');
                }
            }else{
                $this->error('用户不存在');
            }
        // }else{
        //     $this->error('请重新输入正确的验证码');
        // }
    }
    public function captcha(){
        $captcha = new Captcha();
        return $captcha->entry();
    }
}
